package com.example.controller;


import com.example.common.Result;
import com.example.entity.Notice;
import com.example.service.NoticeService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/notice")
public class NoticeController {

    @Resource
    NoticeService noticeService;

    @GetMapping("/selectAll")
    public Result selectAll(Notice notice) {
        return Result.success(noticeService.selectAll(notice));
    }

    @GetMapping("/selectPage")
    public Result selectPage(@RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "3") Integer pageSize,
                             Notice notice) {
        return Result.success(noticeService.selectPage(pageNum, pageSize, notice));
    }

    @PostMapping("/add")
    public Result add(@RequestBody Notice notice) {
        noticeService.add(notice);
        return Result.success("success");
    }

    @PutMapping("/update")
    public Result update(@RequestBody Notice notice) {
        noticeService.update(notice);
        return Result.success("success");
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id) {
        noticeService.deleteById(id);
        return Result.success("success");
    }

    @DeleteMapping("/deleteBatch")
    public Result deleteBatch(@RequestBody List<Notice> noticeList) {
        noticeService.deleteBatch(noticeList);
        return Result.success("success");
    }

}
